<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<!-- 下面这句会自动查找引入进来的工具类脚本。 -->
	<link rel="stylesheet" href="./layui/css/layui.css"  media="all">
	<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>联盟日报</legend>
</fieldset>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
</script>
 
<script src="./layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
 
<script>
layui.use(['table','util','layer'],function(){
	var ws = new WebSocket("ws://192.168.1.116:8080");
	// 连接成功
    ws.onopen = function (e) {
        console.log('连接成功获取到的上半段脚本定义的用户id和type',selfid);
    }
	var table = layui.table;
	var layer = layui.layer;
	var util = layui.util; //注意这行，很重要
	var data_index_first = {"id":selfid};
	console.log(data_index_first,'数据转换');
	layui.jquery.post("/union_data",data_index_first,function(result){
		if(result.status == "success"){
			layer.msg('开始编译一级界面');	// 弹出提示
			console.log(result.data,'有数据吗');
			for(var i = 0; i < result.data[0].length; i++) {
				if(result.data[0][i].is_round_fee == "0") {
					result.data[0][i].is_round_fee = "水上";
				}else if(result.data[0][i].is_round_fee == "1") {
					result.data[0][i].is_round_fee = "每局";
				}
			}
			table.render({
				elem: '#test',
				title: '联盟日报结果',
				totalRow: true,
				cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
				cols: [[
      				{field:'left', title:'操作', toolbar: '#barDemo',width:80,align: 'center'},
					{field:'id', width:80, title:'ID', sort: true,unresize: true,totalRowText: '合计'},
					{field:'is_round_fee', width:80, title: '是否每局抽水', align: 'center'},
					{field:'takein', width:80, title: '总带入', align: 'center',sort: true, totalRow: true},
					{field:'fee', width:80, title: '总抽水(基金收入)', align: 'center',sort: true, totalRow: true},
					{field:'round', width:80, title: '总人数', align: 'center'},
					{field:'player_num', width:80, title: '玩法类型', align: 'center'},
					{field:'room_num', width:80, title: '总房间数', align: 'center',sort: true, totalRow: true},
					{field:'start_time', width:80, title: '开始时间', align: 'center',templet:"<div>{{layui.util.toDateString(d.createTime)}}</div>"},
					{field:'end_time', width:80, title: '结束时间', align: 'center',templet:"<div>{{layui.util.toDateString(d.createTime)}}</div>"},
					{field:'devote', width:80, title: '贡献奖池', align: 'center', sort: true, totalRow: true},
				]],
				data: result.data[0],		// 数据赋值
				page: true,
			});
			//监听行工具事件
			table.on('tool(test)', function(obj){
				var data = obj.data;
				if(obj.event === 'details'){
					var data_index_second = {"id":data.id};
					console.log(data,data_index_second,'有数据吗121');
					layui.jquery.post("/union_data_second",data_index_second,function(result){
						if(result.status == "success"){
							layer.msg('开始编译二级界面');	// 弹出提示
							console.log(result.data,'有数据吗121');
							layer.open({
								// layer提供了5种层类型。{[0:信息框(默认)],[1:页面层],[2:iframe层],[3:加载层],[4:tips层]}
								type: 1,
								title: '显示用户战报',
								shadeClose: false,
								shade: 0.5,
								area: ['100%','100%'],
								content: '<div><table id="testTable"></table></div>',
								success: function(layero, index){
									table.render({
										elem: '#testTable',
										title: '联盟内每个公会的日报',
										cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
										cols: [[
											{field:'id', width:80, title: 'ID', sort: true, align: 'center'},
											{field:'club_id', width:80, title: '公会id', align: 'center'},
											{field:'club_name', width:80, title: '公会名字', align: 'center'},
											{field:'takein', width:80, title: '总带入', align: 'center'},
											{field:'fee', width:80, title: '总抽水', align: 'center'},
											{field:'earn', width:80, title: '总收入', align: 'center'},
											{field:'lost', width:80, title: '总支出', align: 'center'},
											{field:'player_num', width:80, title: '总人数', align: 'center'},
											{field:'devote', width:80, title: '贡献奖池', align: 'center'},
										]],
										data: result.data[0],		// 数据赋值
										page: true,
									})
								},
								end: function () {
									//关闭弹框后事件
								}
							});
						}
					});
				}
			});
		}
		else{
			layer.msg("错误信息:"+result.status);
		}
	});
});
</script>
</body>
</html>